package inventory;

import guitar.Guitar;
import guitar.GuitarSpec;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class Inventory {
    private List guitars;

    public Inventory() {
        guitars = new LinkedList();
    }
    public void addGuitar(String serial, double price, GuitarSpec gc) {
        guitars.add(new Guitar(serial, price, gc));
    }

    public Guitar getGuitar(String serialNumber) {
        for (Iterator i = guitars.iterator(); i.hasNext(); ) {
            Guitar guitar = (Guitar)i.next();
            if (guitar.getSerialNumber().equals(serialNumber))
                return guitar;
        }
        return null;
    }

    public List search(GuitarSpec search) {
        List matchingGuitars = new LinkedList();
        for (Iterator i = guitars.iterator(); i.hasNext(); ) {
            Guitar g = (Guitar)i.next();
            GuitarSpec gc = g.getSpec();
            if (gc.equals(search))
                matchingGuitars.add(g);
        }
        return  matchingGuitars;
    }
}
